/**
 * Project Name:jh
 * File Name:GetConfig.java
 * Package Name:com.jh.utils
 * Date:下午1:36:37
 * Copyright (c) 2021, LZ All Rights Reserved.
 *
*/

package com.jh.utils;

import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jh.comm.RXBQTakeThread;

/**
 * Description: <br/>
 * Date: 下午1:36:37 <br/>
 * 
 * @author lz E-mail:withitren@outlook.com
 * @version
 * @see
 */
public class GetConfig {
    static final Logger logger = LoggerFactory.getLogger(GetConfig.class);

    private GetConfig() {
    }

    private String tcpUrl;

    private int tcpPort;

    private String wsUrl;

    private int wsReconnTimeOut;

    private int rxCapacity;

    private int txCapacity;

    private static GetConfig instance = null;

    public static GetConfig getInstance() {
        if (instance == null) {
            instance = new GetConfig();
        }
        return instance;
    }

    public void init() {
        /*read configuration from Properties*/
        Properties prop = new Properties();
        try {
            prop.load(RXBQTakeThread.class.getResourceAsStream("/appConfig.properties"));
            // throw new Exception("OK!");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        String url = prop.getProperty("tcpUrl", "localhost");
        setTcpUrl(url);

        String portStr = prop.getProperty("tcpPort", "8899");
        int port = Integer.parseInt(portStr);
        setTcpPort(port);

        String wsUrlTmp = prop.getProperty("wsUrl", "ws://localhost:8080/jh/radar");
        setWsUrl(wsUrlTmp);

        String wsReconnTimeOutStrTmp = prop.getProperty("wsReconnTimeOut", "30000");
        setWsReconnTimeOut(Integer.parseInt(wsReconnTimeOutStrTmp));

        String rxCapacityTmp = prop.getProperty("rxCapacity", "9");
        String txCapacityTmp = prop.getProperty("txCapacity", "9");
        int rxCapacityInt = Integer.parseInt(rxCapacityTmp);
        int txCapacityInt = Integer.parseInt(txCapacityTmp);
        setRxCapacity(rxCapacityInt);
        setTxCapacity(txCapacityInt);
    }

    public String getTcpUrl() {
        return tcpUrl;
    }

    public void setTcpUrl(String tcpUrl) {
        this.tcpUrl = tcpUrl;
    }

    public int getTcpPort() {
        return tcpPort;
    }

    public void setTcpPort(int tcpPort) {
        this.tcpPort = tcpPort;
    }

    public String getWsUrl() {
        return wsUrl;
    }

    public void setWsUrl(String wsUrl) {
        this.wsUrl = wsUrl;
    }

    public int getWsReconnTimeOut() {
        return wsReconnTimeOut;
    }

    public void setWsReconnTimeOut(int wsReconnTimeOut) {
        this.wsReconnTimeOut = wsReconnTimeOut;
    }

    public int getRxCapacity() {
        return rxCapacity;
    }

    public void setRxCapacity(int rxCapacity) {
        this.rxCapacity = rxCapacity;
    }

    public int getTxCapacity() {
        return txCapacity;
    }

    public void setTxCapacity(int txCapacity) {
        this.txCapacity = txCapacity;
    }

}
